package com.miku.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.miku.db.define.CodeDef;
import com.miku.utils.resp.Echo;

public class RespUtils {
	public static final String success = "success";
	public static final String fail = "fail";
	
	public static<T> String respSuccess(T obj){
		return JSON.toJSONString(new Echo<T>(CodeDef.echoSuccess, obj));
	}
	
	/**
	 * 返回消息，当msg为null的时候，为fail，否则是success
	 * @param msg
	 * @return
	 */
	public static<T> String respMsg(T obj, SerializerFeature... feature){
		return JSON.toJSONString(new Echo<T>(obj == null ? CodeDef.echoFailure : CodeDef.echoSuccess, obj), feature);
	}
	
	public static<T> String respFail(T obj){
		return JSON.toJSONString(new Echo<T>(CodeDef.echoFailure, obj));
	}
}
